package com.leetcode.no589;

import java.util.*;

class Node {
    public int val;
    public List<Node> children;

    public Node() {
    }

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};

public class Solution {
    List<Integer> res = new ArrayList<>();

    public List<Integer> preorder(Node root) {
        if (root == null) {
            return res;
        }
        helper(root);
        return res;
    }

    void helper(Node root) {
        if (root == null) {
            return;
        }
        res.add(root.val);
        for(Node oneNode: root.children){
            if(oneNode != null){
                helper(oneNode);
            }
        }
    }
}
